//
//  LGKNoteEditViewController.m
//  LGKNote
//
//  Created by 刘亚军 on 2023/5/29.
//

#import "LGKNoteEditViewController.h"
#import "LGKConst.h"
#import "LGKNoteTextField.h"
#import "LGKNotePhotoManager.h"
#import <WebKit/WebKit.h>
#import "LGRichTextToolBar.h"
#import "WKWebView+WGWKWebViewExtension.h"
#import "LGKNoteUploadModel.h"
#import "LGKNoteEditDataModel.h"
#import "LGKNoteWebView.h"
#import "LGNDrawBoardViewController.h"
@interface LGKNoteEditViewController ()<WKNavigationDelegate,WKUIDelegate,LGRichTextToolBarDelegate,LGKNotePhotoManagerDelegate,LGKNoteTextFieldDelegate>
@property (nonatomic,strong) UIView *headerView;
@property (nonatomic,strong) UIImageView *menuImgView;
@property (nonatomic,strong) UILabel *subjectNameLab;
@property (nonatomic,strong) UIButton *sourceBtn;
@property (nonatomic,strong) UIButton *saveBtn;
@property (nonatomic,strong) UIButton *markBtn;
@property (nonatomic,strong) LGKNoteTextField *titleTextField;
@property (nonatomic,strong) LGKNoteEditDataModel *editDM;
@property (nonatomic,strong) WKWebView *webView;
@property (nonatomic,strong) LGRichTextToolBar *toolBar;
@property (nonatomic,assign) CGFloat keboardHeight;
@property (nonatomic,strong) NSMutableArray<LGKNoteUploadModel *> *uploadArr;
@property (nonatomic,assign) CGFloat lastPostion;
@property (nonatomic,assign) CGFloat webViewHeight;
@property (nonatomic,assign) BOOL updated;
@end

@implementation LGKNoteEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.editDM = (LGKNoteEditDataModel *)self.dataModel;
    [LGKNotePhotoManager manage].ownController = self;
    [LGKNotePhotoManager manage].delegate = self;
    self.closeSideslip = YES;
    if(self.editModel){
        [self layoutUI];
    }else{
        [self yj_loadGifData];
    }
}
- (void)yj_updateData{
    self.editModel = (LGKNoteEditModel *)self.dataModel.model;
    [self layoutUI];
}
- (void)layoutUI{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.saveBtn];
    [self.view addSubview:self.headerView];
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.mas_equalTo(44);
    }];
    [self.headerView addSubview:self.menuImgView];
    [self.menuImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headerView);
        make.left.equalTo(self.headerView).offset(10);
        make.height.width.mas_equalTo(16);
    }];
    [self.headerView addSubview:self.subjectNameLab];
    [self.subjectNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.headerView);
        make.left.equalTo(self.menuImgView.mas_right).offset(3);
    }];
    
    [self.headerView addSubview:self.sourceBtn];
    [self.sourceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.top.equalTo(self.headerView);
        make.width.mas_lessThanOrEqualTo(LG_ScreenWidth*0.7);
        make.right.equalTo(self.headerView).offset(-10);
    }];
    self.sourceBtn.enabled = !IsStrEmpty(self.editModel.ResourceName) && LGKNoteManager.defaultManager.noteParams.isMyNoteEnter && self.editModel.supportJump;
    [self.sourceBtn setTitle:IsStrEmpty(self.editModel.ResourceName) ? @"我的笔记" : self.editModel.showResourceName forState:UIControlStateNormal];
    UIView *line1 = [UIView new];
    line1.backgroundColor = LG_ColorWithHex(0xf5f5f5);
    [self.view addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.mas_bottom);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(8);
    }];
    [self.view addSubview:self.titleTextField];
    [self.titleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(10);
        make.top.equalTo(line1.mas_bottom).offset(5);
        make.right.equalTo(self.view).offset(-40);
        make.height.mas_equalTo(26);
    }];
    
    [self.view addSubview:self.markBtn];
    [self.markBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(-10);
        make.centerY.equalTo(self.titleTextField);
        make.width.height.mas_equalTo(28);
    }];
    
    UIView *line2 = [UIView new];
    line2.backgroundColor = LG_ColorWithHex(0xf5f5f5);
    [self.view addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleTextField.mas_bottom).offset(5);
        make.left.right.equalTo(self.view).offset(10);
        make.height.mas_equalTo(0.8);
    }];
    CGFloat y = 44 + 8 + 26 + 5 + 5 + 1;
    self.webViewHeight = LG_ScreenHeight - LG_STATUS_AND_NAVIGATION_BAR_HEIGHT - y;
    self.webView.frame = CGRectMake(0, y, LG_ScreenWidth, self.webViewHeight);
    self.webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
    [self.view addSubview:self.webView];
    [self.view addSubview:self.toolBar];
    
    NSString * htmlCont = [NSString stringWithContentsOfFile:[LGKNoteManager.defaultManager.noteBundle pathForResource:@"JS/RichEditor.html" ofType:nil] encoding:NSUTF8StringEncoding error:nil];
    NSString *path = [[LGKNoteManager.defaultManager.noteBundle bundlePath] stringByAppendingPathComponent:@"JS"];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [self.webView loadHTMLString:htmlCont baseURL:baseURL];
    
    if (!IsStrEmpty(self.editModel.NoteContent)){
        self.titleTextField.text = self.editModel.NoteTitle;
        self.markBtn.selected = self.editModel.IsKeyPoint;
    }
    //键盘高度处理
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)navBar_leftItemPressed:(UIBarButtonItem *)sender{
    if (self.updated){
        __weak typeof(self) weakSelf = self;
        LGAlertManager.alert.config.LgImageType(LGHeaderImageTypeQuestion).LgTitle(@"提示").LgContent(@"笔记未保存，确定要退出吗？").LgCancelAction(@"取消", ^{}).LgAction(@"退出", ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }).LgShow();
    }else{
        [super navBar_leftItemPressed:sender];
    }
}
- (void)saveBtnClickAction{
    if(IsStrEmpty(self.titleTextField.text)){
        [LGAlert showInfoWithStatus:@"笔记标题不能为空"];
        return;
    }
    if ([self isUploadResult]) {
        [LGAlert showInfoWithStatus:@"图片未上传成功"];
        return;
    }
    __weak typeof(self) weakSelf = self;
    [self.webView contentHtmlTextHandleCallback:^(id  _Nullable obj, NSError * _Nullable error) {
        if (!error){
            if(IsStrEmpty(obj)){
                [LGAlert showInfoWithStatus:@"笔记内容不能为空"];
            }else{
                [weakSelf uploadNoteDataWithNoteContent:obj];
            }
        }else{
            [LGAlert showInfoWithStatus:@"无法获取笔记内容"];
        }
    }];
}
- (void)uploadNoteDataWithNoteContent:(NSString *)noteContent{
    [LGAlert showIndeterminate];
    NSDictionary *params = @{
        @"NoteID":kApiParams(self.editModel.NoteID),
        @"UserID":kApiParams(LGKNoteManager.defaultManager.userID),
        @"SysID":kApiParams(self.editModel.SysID),
        @"SchoolID":kApiParams(LGKNoteManager.defaultManager.schoolID),
        @"ResourceID":kApiParams(self.editModel.ResourceID),
        @"ResourceName":kApiParams(self.editModel.ResourceName),
        @"MaterialID":kApiParams(self.editModel.MaterialID),
        @"MaterialName": kApiParams(self.editModel.MaterialName),
        @"IsKeyPoint":@(self.markBtn.selected ? 1 : 0),
        @"NoteTitle":self.titleTextField.text,
        @"NoteContent":noteContent.yj_htmlDecode,
    };
    __weak typeof(self) weakSelf = self;
    [self.editDM saveNoteWithParams:params completion:^(NSString * _Nullable noteID) {
        if (!IsStrEmpty(noteID)){
            [LGAlert hide];
            if (weakSelf.updateBlock){
                weakSelf.updateBlock();
            }
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else{
            [LGAlert showErrorWithStatus:@"保存失败"];
        }
    }];
}
- (void)sourceBtnClickAction{
    NSDictionary *params = @{
        @"sysID":kApiParams(self.editModel.SysID),
        @"resourceID":kApiParams(self.editModel.ResourceID),
        @"resourceName":kApiParams(self.editModel.ResourceName),
        @"materialID":kApiParams(self.editModel.MaterialID),
        @"materialName": kApiParams(self.editModel.MaterialName)
    };
    if (LGKNoteManager.defaultManager.notePresentBlock){
        LGKNoteManager.defaultManager.notePresentBlock(params,self);
    }
    if (LGKNoteManager.defaultManager.notePushBlock){
        LGKNoteManager.defaultManager.notePushBlock(params,self);
    }
}
- (void)markBtnClickAction{
    self.markBtn.selected = !self.markBtn.selected;
    [LGAlert showSuccessWithStatus:self.markBtn.selected ? @"已标记为重点" : @"已取消标记"];
}
- (void)getHTML{
    if ([self isUploadResult]) {
        [LGAlert showInfoWithStatus:@"图片未上传成功"];
        return;
    }
    [self.webView contentHtmlTextHandleCallback:^(id  _Nullable obj, NSError * _Nullable error) {
        if (!error){
            
        }else{
            [LGAlert showInfoWithStatus:@"无法获取笔记内容"];
        }
    }];
}
- (void)keyBoardWillChangeFrame:(NSNotification*)notification{
    if (!self.titleTextField.isFirstResponder){
        self.updated = YES;
    }
    CGRect frame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    self.keboardHeight = frame.size.height;
    CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGFloat toolBarHeight = self.toolBar.frame.size.height;
    if (frame.origin.y == LG_ScreenHeight) {
        [UIView animateWithDuration:duration animations:^{
            self.toolBar.y =  self.view.height;
            [self.webView setHeight: self.webViewHeight];
        }];
    }else{
        [UIView animateWithDuration:duration animations:^{
            self.toolBar.y = self.view.height - self.keboardHeight-LGRichTextToolBarH;
            [self.webView setHeight:self.webViewHeight - self.keboardHeight-toolBarHeight];
        }];
    }
}
#pragma mark - LGKNoteTextFieldDelegate
- (BOOL)yj_textFieldShouldBeginEditing:(LGKNoteTextField *)textField{
    self.toolBar.hidePhotoTool = YES;
    return YES;
}
- (BOOL)yj_textFieldShouldEndEditing:(LGKNoteTextField *)textField{
    self.toolBar.hidePhotoTool = NO;
    return YES;
}
- (void)yj_textFieldDidEndEditing:(LGKNoteTextField *)textField{
    self.updated = YES;
}
#pragma mark - UserPhotoManagerDelegate
- (void)LGKNotePhotoManager:(LGKNotePhotoManager *)manage cameraDidSelectImage:(UIImage *)selectImage{
    UIImage *image = selectImage;
    LGNDrawBoardViewController *drawController = [[LGNDrawBoardViewController alloc] init];
    drawController.style = LGNoteDrawBoardViewControllerStyleDefault;
    drawController.isCamera = YES;
    drawController.size = image.size;
    drawController.drawBgImage = image;
    __weak typeof(self) weakSelf = self;
    drawController.drawResultBlock = ^(UIImage *image) {
        [weakSelf uploadPictureImage:image];
    };
    drawController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:drawController animated:YES completion:nil];
}
- (void)LGKNotePhotoManager:(LGKNotePhotoManager *)manage albumDidSelectImage:(NSArray *)selectImages{
    UIImage *image = selectImages.firstObject;
    LGNDrawBoardViewController *drawController = [[LGNDrawBoardViewController alloc] init];
    drawController.style = LGNoteDrawBoardViewControllerStyleDefault;
    drawController.isCamera = NO;
    drawController.size = image.size;
    drawController.drawBgImage = image;
    __weak typeof(self) weakSelf = self;
    drawController.drawResultBlock = ^(UIImage *image) {
        [weakSelf uploadPictureImage:image];
    };
    drawController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:drawController animated:YES completion:nil];
}

-(void)uploadPictureImage:(UIImage *)selImg{
    LGKNoteUploadModel *fileM = [LGKNoteUploadModel new];
    fileM.fileData = UIImageJPEGRepresentation(selImg,0.8f);
    fileM.image = selImg;
    fileM.key = fileM.uuid;
    [self.uploadArr addObject:fileM];
    [self.webView insetImage:fileM.fileData key:fileM.key];
    __weak typeof(self) weakSelf = self;
    [self.editDM uploadImgWithImgArr:@[fileM.image] progressBlock:^(CGFloat progress) {
        //正在上传
        [weakSelf.webView insetImageKey:fileM.key progress:progress];
    } complete:^(NSArray * _Nullable imgUrls) {
        if (!IsArrEmpty(imgUrls)){
            //上传成功
            fileM.state = LGKNoteUploadStateSuccess;
            fileM.imgUrl = imgUrls.firstObject;
            [weakSelf.webView insetSuccessImageKey:fileM.key imgUrl:fileM.imgUrl];
        }else{
            [weakSelf.webView setupContentDisable:true];
            //上传失败
            fileM.state = LGKNoteUploadStateError;
            [weakSelf.webView uploadErrorKey:fileM.key];
        }
    }];
}
//判断是否有上传失败的图片
- (BOOL)isUploadResult{
    if (self.uploadArr<=0) {return NO;}
    BOOL result = NO;
    for (LGKNoteUploadModel *fileM in self.uploadArr) {
        if (fileM.state != LGKNoteUploadStateSuccess) {
            result = YES;
            break;
        }
    }
    return result;
}
//返回对应的模型
- (LGKNoteUploadModel *)fileModelWithKey:(NSString *)key{
    if(self.uploadArr.count<=0) return nil;
    LGKNoteUploadModel *upfileM;
    for (LGKNoteUploadModel *fileM in self.uploadArr) {
        if([fileM.key isEqualToString:key]){
            upfileM = fileM;
            break;
        }
    }
    return upfileM;
}
#pragma mark - LGRichTextToolBarDelegate
- (void)LGRichTextToolBarCamera{
    [[LGKNotePhotoManager manage] photoFromCamera];
}
- (void)LGRichTextToolBarPhoto{
    [[LGKNotePhotoManager manage] photoFromAlbum];
}
- (void)LGRichTextToolBarDrawBoard{
    LGNDrawBoardViewController *drawController = [[LGNDrawBoardViewController alloc] init];
    drawController.style = LGNoteDrawBoardViewControllerStyleDraw;
    drawController.modalPresentationStyle = UIModalPresentationFullScreen;
    __weak typeof(self) weakSelf = self;
    drawController.drawResultBlock = ^(UIImage *image) {
        [weakSelf uploadPictureImage:image];
    };
    [self presentViewController:drawController animated:YES completion:nil];
}
- (void)LGRichTextToolBarDone{
    [self.view endEditing:YES];
}
#pragma mark - 图片操作
- (BOOL)handleWithString:(NSString *)urlString{
    if ([urlString hasPrefix:@"protocol://iOS?code=uploadResult&data="]){
        //获取当前
          NSRange range = [urlString rangeOfString:@"protocol://iOS?code=uploadResult&data="];
      
        NSString *dictString = [urlString substringFromIndex:range.length];
        
        NSLog(@"截取后：%@",dictString);
        NSDictionary *dict = [LGKNoteUploadModel jsonObject:[dictString stringByRemovingPercentEncoding]];
        if(dict[@"imgId"]) {
            NSLog(@"click = %@",dict[@"imgId"]);
            LGKNoteUploadModel *imgM = [self fileModelWithKey:dict[@"imgId"]];
            if(imgM.state == LGKNoteUploadStateError){
                [self actionSheetWitType:1 handleFileM:imgM];
            }else if(imgM.state == LGKNoteUploadStateSuccess){
                [self actionSheetWitType:2 handleFileM:imgM];
            }
        }
        return NO;
    }
    return YES;
}
- (void)actionSheetWitType:(NSInteger)type handleFileM:(LGKNoteUploadModel *)fileM{
    
    NSString *btnTitle = type == 1?@"重新上传":@"删除";
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"操作提示" preferredStyle:UIAlertControllerStyleActionSheet];
    
    __weak typeof(self) weakSelf = self;
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:btnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (type == 1) {
            //移除失败样式
            [self.webView removeBtnErrorKey:fileM.key isHide:TRUE];
            //重传
            [weakSelf.editDM uploadImgWithImgArr:@[fileM.image] progressBlock:^(CGFloat progress) {
                //正在上传
                [weakSelf.webView insetImageKey:fileM.key progress:progress];
            } complete:^(NSArray * _Nullable imgUrls) {
                if (!IsArrEmpty(imgUrls)){
                    //上传成功
                    fileM.state = LGKNoteUploadStateSuccess;
                    fileM.imgUrl = imgUrls.firstObject;
                    [weakSelf.webView insetSuccessImageKey:fileM.key imgUrl:fileM.imgUrl];
                }else{
                    //上传失败
                    fileM.state = LGKNoteUploadStateError;
                    [weakSelf.webView uploadErrorKey:fileM.key];
                }
            }];
        }else{
            //删除
            [self.webView deleteImageKey:fileM.key];
            [self.uploadArr enumerateObjectsUsingBlock:^(LGKNoteUploadModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([fileM.key isEqualToString:obj.key]) {
                    [weakSelf.uploadArr removeObject:fileM];
                    *stop = YES;
                }
            }];
        }
        
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVc addAction:okAction];
    [alertVc addAction:cancelAction];
    
    [self presentViewController:alertVc animated:YES completion:^{
        [self.webView setupContentDisable:TRUE];
    }];
}
#pragma mark - WebViewDelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
}
- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler{
    NSString *urlString = navigationAction.request.URL.absoluteString;
    NSLog(@"decidePolicyForNavigationAction = %@",urlString);
    [self.webView updatePlaceHolderStatu];
    [self handleWithString:urlString];
    __weak typeof(self) weakSelf = self;
    [webView getCaretYPositionPositionHandleCallback:^(id  _Nullable obj, NSError * _Nullable error) {
       CGFloat currentPos = [obj floatValue];
        if (weakSelf.lastPostion != currentPos) {
            weakSelf.lastPostion = currentPos;
            CGFloat offset = currentPos - (self.webViewHeight - weakSelf.keboardHeight - 49);
            if (offset > 0) {
                [weakSelf.webView autoScrollTop:offset];
            }
        }
    }];
    decisionHandler(WKNavigationActionPolicyAllow); // 必须实现 加载
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    if (!IsStrEmpty(self.editModel.NoteContent)){
        [self.webView setupContent:self.editModel.NoteContent];
        [self.webView placeHolderWithHidden:YES];
    }
}

- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error{
    
}
#pragma mark - lazy
- (NSMutableArray<LGKNoteUploadModel *> *)uploadArr{
    if (!_uploadArr){
        _uploadArr = [[NSMutableArray<LGKNoteUploadModel *> alloc] init];
    }
    return _uploadArr;
}

- (WKWebView *)webView{
    if (!_webView) {
        _webView = [[WKWebView alloc] init];
        _webView.navigationDelegate = self;
        _webView.scrollView.bounces = NO;
        _webView.hidesInputAccessoryView = YES;
    }
    return _webView;
}
- (LGRichTextToolBar *)toolBar{
    if (!_toolBar){
        _toolBar = [[LGRichTextToolBar alloc] initWithFrame:CGRectMake(0,self.view.height, LG_ScreenWidth, LGRichTextToolBarH)];
        _toolBar.delegate = self;
    }
    return _toolBar;
}
- (UIView *)headerView{
    if (!_headerView){
        _headerView = [UIView new];
        _headerView.backgroundColor = UIColor.whiteColor;
    }
    return _headerView;
}
- (UIImageView *)menuImgView{
    if(!_menuImgView){
        _menuImgView = [[UIImageView alloc] initWithImage:[UIImage yj_imageNamed:@"note_subject" atBundle:LGKNoteManager.defaultManager.noteBundle]];
    }
    return _menuImgView;
}
- (UILabel *)subjectNameLab{
    if (!_subjectNameLab){
        _subjectNameLab = UILabel.new;
        _subjectNameLab.text = LGKNoteManager.defaultManager.subjectName;
        _subjectNameLab.font = LG_SysFont(13);
        _subjectNameLab.textColor = LG_ColorWithHex(0x2DA8FF);
    }
    return _subjectNameLab;
}
- (UIButton *)sourceBtn{
    if(!_sourceBtn){
        _sourceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sourceBtn setTitleColor:LG_ColorWithHex(0x999999) forState:UIControlStateDisabled];
        [_sourceBtn setTitleColor:LG_ColorWithHex(0xFF7017) forState:UIControlStateNormal];
        [_sourceBtn addTarget:self action:@selector(sourceBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
        _sourceBtn.titleLabel.font = LG_SysFont(13);
    }
    return _sourceBtn;
}
- (UIButton *)markBtn{
    if (!_markBtn){
        _markBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_markBtn setImage:[UIImage yj_imageNamed:@"note_remark_unselected" atBundle:LGKNoteManager.defaultManager.noteBundle] forState:UIControlStateNormal];
        [_markBtn setImage:[UIImage yj_imageNamed:@"note_remark_selected" atBundle:LGKNoteManager.defaultManager.noteBundle] forState:UIControlStateSelected];
        [_markBtn addTarget:self action:@selector(markBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _markBtn;
}
- (UIButton *)saveBtn{
    if (!_saveBtn){
        _saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _saveBtn.frame = CGRectMake(0, 0, 40, 28);
        [_saveBtn setTitle:@"完成" forState:UIControlStateNormal];
        [_saveBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [_saveBtn addTarget:self action:@selector(saveBtnClickAction) forControlEvents:UIControlEventTouchUpInside];
        _saveBtn.titleLabel.font = LG_SysFont(16);
    }
    return _saveBtn;
}
- (LGKNoteTextField *)titleTextField{
    if (!_titleTextField){
        _titleTextField = [[LGKNoteTextField alloc] initWithFrame:CGRectZero];
        _titleTextField.maxLength = 50;
        _titleTextField.limitType = LGKNoteTextFieldLimitEmojiLimit;
        _titleTextField.textColor = LG_ColorWithHex(0x252525);
        _titleTextField.tintColor = LG_ColorWithHex(0x2A61F2);
        _titleTextField.font = LG_SysFont(17);
        [_titleTextField deleteAccessoryView];
        NSMutableAttributedString *attr = @"请输入笔记标题(50字内)".yj_toMutableAttributedString;
        [attr yj_setColor:LG_ColorWithHex(0xd0d0d0)];
        [attr yj_setFont:17];
        _titleTextField.attributedPlaceholder = attr;
        _titleTextField.yjDelegate = self;
    }
    return _titleTextField;
}

@end
